//
//  BaseViewController.swift
//  XLWB
//
//  Created by 郭亮 on 16/3/14.
//  Copyright © 2016年 gl. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    //MARK:-懒加载属性
    lazy var visitorView: VisitorView = VisitorView.visitorView()
    
    //MARK:-属性
    var isLogin: Bool = UserAccountViewModal.shareInstance.isLogin
    
    //系统回调函数
    override func loadView() {
        isLogin ? super.loadView() : loadVisitorView()
    }
}

// MARK:-加载访客视图
extension BaseViewController {
    private func loadVisitorView() {
    view = visitorView
        //设置导航条
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "registerBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "loginBtnClick")
        //按钮点击
        visitorView.registerBtn.addTarget(self, action: "registerBtnClick", forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: "loginBtnClick", forControlEvents: .TouchUpInside)
    }
}

// MARK:-按钮点击
extension BaseViewController {
    @objc private func registerBtnClick() {
        print("registerBtnClick")
    }
    
    @objc private func loginBtnClick() {
        //弹出授权页面
        let oauth = OauthViewController()
        let navVc = UINavigationController(rootViewController: oauth)
        presentViewController(navVc, animated: true, completion: nil)
    }
}







